package de.hhbk.feedbackmodul.beans.applicationscope;

import java.util.ArrayList;
import java.util.List;

import javax.annotation.PostConstruct;
import javax.naming.NamingException;

import org.apache.log4j.Logger;

import de.hhbk.feedbackmodul.entities.Answer;
import de.hhbk.feedbackmodul.entities.AnswerPossibility;
import de.hhbk.feedbackmodul.entities.AnswerSheet;
import de.hhbk.feedbackmodul.entities.Participant;
import de.hhbk.feedbackmodul.entities.Question;
import de.hhbk.feedbackmodul.entities.QuestionSheet;
import de.hhbk.feedbackmodul.entities.Survey;
import de.hhbk.feedbackmodul.entities.Tan;
import de.hhbk.feedbackmodul.entities.User;
import de.hhbk.feedbackmodul.entities.UserRole;
import de.hhbk.feedbackmodul.remoteInterfaces.AnswerPossibilityRemoteIF;
import de.hhbk.feedbackmodul.remoteInterfaces.AnswerRemoteIF;
import de.hhbk.feedbackmodul.remoteInterfaces.AnswerSheetRemoteIF;
import de.hhbk.feedbackmodul.remoteInterfaces.ParticipantRemoteIF;
import de.hhbk.feedbackmodul.remoteInterfaces.QuestionRemoteIF;
import de.hhbk.feedbackmodul.remoteInterfaces.QuestionSheetRemoteIF;
import de.hhbk.feedbackmodul.remoteInterfaces.SurveyRemoteIF;
import de.hhbk.feedbackmodul.remoteInterfaces.TanRemoteIF;
import de.hhbk.feedbackmodul.remoteInterfaces.UserRemoteIF;
import de.hhbk.feedbackmodul.remoteInterfaces.UserRoleRemoteIF;
import de.hhbk.feedbackmodul.util.JBossServiceLocator;
import de.hhbk.feedbackmodul.utilInterfaces.ServiceLocator;


public class ApplicationManagerBean {

	private ServiceLocator servicelocator;
	
	private Logger logger;
	
	private List<User> userlist;
	
	private List<UserRole> userRoleList;
	
	private List<Question> questionList;
	
	private List<Answer> answerList;
	
	private List<AnswerPossibility> answerPossibilityList;
	
	private List<AnswerSheet> answerSheetList;
	
	private List<QuestionSheet> questionSheetList;
	
	private List<Participant> participantList;
	
	private List<Survey> surveyList;
	
	private List<Tan> tanList;
	
	@PostConstruct
	public void init()
	{
		logger = Logger.getLogger(this.getClass());
		servicelocator = JBossServiceLocator.getInstance();
		
		userlist = new ArrayList<User>();
		userRoleList = new ArrayList<UserRole>();
		questionList = new ArrayList<Question>();
		answerList = new ArrayList<Answer>();
		answerPossibilityList = new ArrayList<AnswerPossibility>();
		answerSheetList = new ArrayList<AnswerSheet>();
		questionSheetList = new ArrayList<QuestionSheet>();
		participantList = new ArrayList<Participant>();
		surveyList = new ArrayList<Survey>();
		tanList = new ArrayList<Tan>();
		synchronized (userlist) {
			userlist = getAllUser();
		}
		synchronized (userRoleList) {
			userRoleList = getAllUserRoles();
		}
		synchronized (questionList) {
			questionList = getAllQuestions();
		}
		synchronized (answerList) {
			answerList = getAllAnswers();
		}
		synchronized (answerPossibilityList) {
			answerPossibilityList = getAllAnswerPossibilities();
		}
		synchronized (answerSheetList) {
			answerSheetList = getAllAnswerSheets();
		}
		synchronized (questionSheetList) {
			questionSheetList = getAllQuestionSheets();
		}
		synchronized (participantList) {
			participantList = getAllParticipants();
		}
		synchronized (surveyList) {
			surveyList = getAllSurveys();	
		}
		synchronized (tanList) {
			tanList = getAllTans();	
		}
	}

	
	/* Database ACCESS */
	
	/* LESEZUGRIFF */
	
	private List<User> getAllUser()
	{
		try
		{
			UserRemoteIF remote = (UserRemoteIF) servicelocator.lookup("java:jboss/exported/FeebackModulEAR/FeedbackModulEJB/UserSessionBean!de.hhbk.feedbackmodul.remoteInterfaces.UserRemoteIF", UserRemoteIF.class);
			List<User> list = remote.getAllUsers();
			return list;
		}
		catch(NamingException e)
		{
			logger.error("Exception while looking up to the remote Interface 'UserRemoteIF': "+e.getMessage(),e);
			
		} 
		catch (Exception e)
		{
			logger.error("Exception while reading User from RemotInterface: "+e.getMessage(),e);
		}
		return new ArrayList<User>();
	}
	
	private List<UserRole> getAllUserRoles()
	{
		try
		{
			UserRoleRemoteIF remote = (UserRoleRemoteIF) servicelocator.lookup("java:jboss/exported/FeebackModulEAR/FeedbackModulEJB/UserRoleSessionBean!de.hhbk.feedbackmodul.remoteInterfaces.UserRoleRemoteIF", UserRoleRemoteIF.class);
			List<UserRole> list = remote.getAllUserRoles();
			return list;
		}
	
		catch(NamingException e)
		{
			logger.error("Exception while looking up to the remote Interface 'UserRoleRemoteIF': "+e.getMessage(),e);
			
		} 
		catch (Exception e)
		{
			logger.error("Exception while reading UserRoles from RemotInterface: "+e.getMessage(),e);
		}
		return new ArrayList<UserRole>();	
	}
	
	private List<Question> getAllQuestions()
	{
		try
		{
			QuestionRemoteIF remote = (QuestionRemoteIF) servicelocator.lookup("java:jboss/exported/FeebackModulEAR/FeedbackModulEJB/QuestionSessionBean!de.hhbk.feedbackmodul.remoteInterfaces.QuestionRemoteIF", QuestionRemoteIF.class);
			List<Question> list = remote.getAllQuestions();
			return list;
		}
	
		catch(NamingException e)
		{
			logger.error("Exception while looking up to the remote Interface 'QuestionRemoteIF': "+e.getMessage(),e);
			
		} 
		catch (Exception e)
		{
			logger.error("Exception while reading Questions from RemotInterface: "+e.getMessage(),e);
		}
		return new ArrayList<Question>();	
	}
	
	private List<Answer> getAllAnswers()
	{
		try
		{
			AnswerRemoteIF remote = (AnswerRemoteIF) servicelocator.lookup("java:jboss/exported/FeebackModulEAR/FeedbackModulEJB/AnswerSessionBean!de.hhbk.feedbackmodul.remoteInterfaces.AnswerRemoteIF", AnswerRemoteIF.class);
			List<Answer> list = remote.getAllAnswers();
			return list;
		}
	
		catch(NamingException e)
		{
			logger.error("Exception while looking up to the remote Interface 'AnswerRemoteIF': "+e.getMessage(),e);
			
		} 
		catch (Exception e)
		{
			logger.error("Exception while reading Answers from RemotInterface: "+e.getMessage(),e);
		}
		return new ArrayList<Answer>();	
	}
	
	private List<AnswerPossibility> getAllAnswerPossibilities()
	{
		try
		{
			AnswerPossibilityRemoteIF remote = (AnswerPossibilityRemoteIF) servicelocator.lookup("java:jboss/exported/FeebackModulEAR/FeedbackModulEJB/AnswerPossibilitySessionBean!de.hhbk.feedbackmodul.remoteInterfaces.AnswerPossibilityRemoteIF", AnswerPossibilityRemoteIF.class);
			List<AnswerPossibility> list = remote.getAllAnswerPossibilities();
			return list;
		}
	
		catch(NamingException e)
		{
			logger.error("Exception while looking up to the remote Interface 'AnswerPossibilityRemoteIF': "+e.getMessage(),e);
			
		} 
		catch (Exception e)
		{
			logger.error("Exception while reading AnswerPossibilities from RemotInterface: "+e.getMessage(),e);
		}
		return new ArrayList<AnswerPossibility>();	
	}
	
	private List<AnswerSheet> getAllAnswerSheets()
	{
		try
		{
			AnswerSheetRemoteIF remote = (AnswerSheetRemoteIF) servicelocator.lookup("java:jboss/exported/FeebackModulEAR/FeedbackModulEJB/AnswerSheetSessionBean!de.hhbk.feedbackmodul.remoteInterfaces.AnswerSheetRemoteIF", AnswerSheetRemoteIF.class);
			List<AnswerSheet> list = remote.getAllAnswerSheets();
			return list;
		}
	
		catch(NamingException e)
		{
			logger.error("Exception while looking up to the remote Interface 'AnswerSheetRemoteIF': "+e.getMessage(),e);
			
		} 
		catch (Exception e)
		{
			logger.error("Exception while reading AnswerSheets from RemotInterface: "+e.getMessage(),e);
		}
		return new ArrayList<AnswerSheet>();	
	}
	
	private List<QuestionSheet> getAllQuestionSheets()
	{
		try
		{
			QuestionSheetRemoteIF remote = (QuestionSheetRemoteIF) servicelocator.lookup("java:jboss/exported/FeebackModulEAR/FeedbackModulEJB/QuestionSheetSessionBean!de.hhbk.feedbackmodul.remoteInterfaces.QuestionSheetRemoteIF", QuestionSheetRemoteIF.class);
			List<QuestionSheet> list = remote.getAllQuestionSheets();
			return list;
		}
	
		catch(NamingException e)
		{
			logger.error("Exception while looking up to the remote Interface 'QuestionSheetRemoteIF': "+e.getMessage(),e);
			
		} 
		catch (Exception e)
		{
			logger.error("Exception while reading QuestionSheets from RemotInterface: "+e.getMessage(),e);
		}
		return new ArrayList<QuestionSheet>();	
	}
	
	private List<Participant> getAllParticipants()
	{
		try
		{
			ParticipantRemoteIF remote = (ParticipantRemoteIF) servicelocator.lookup("java:jboss/exported/FeebackModulEAR/FeedbackModulEJB/ParticipantSessionBean!de.hhbk.feedbackmodul.remoteInterfaces.ParticipantRemoteIF", ParticipantRemoteIF.class);
			List<Participant> list = remote.getAllParticipants();
			return list;
		}
	
		catch(NamingException e)
		{
			logger.error("Exception while looking up to the remote Interface 'ParticipantRemoteIF': "+e.getMessage(),e);
			
		} 
		catch (Exception e)
		{
			logger.error("Exception while reading Participants from RemotInterface: "+e.getMessage(),e);
		}
		return new ArrayList<Participant>();	
	}
	
	private List<Survey> getAllSurveys()
	{
		try
		{
			SurveyRemoteIF remote = (SurveyRemoteIF) servicelocator.lookup("java:jboss/exported/FeebackModulEAR/FeedbackModulEJB/SurveySessionBean!de.hhbk.feedbackmodul.remoteInterfaces.SurveyRemoteIF", SurveyRemoteIF.class);
			List<Survey> list = remote.getAllSurveys();
			return list;
		}
		catch(NamingException e)
		{
			logger.error("Exception while looking up to the remote Interface 'SurveyRemoteIF': "+e.getMessage(),e);
			
		} 
		catch (Exception e)
		{
			logger.error("Exception while reading Surveys from RemotInterface: "+e.getMessage(),e);
		}
		return new ArrayList<Survey>();	
	}
	
	private List<Tan> getAllTans()
	{
		try
		{
			TanRemoteIF remote = (TanRemoteIF) servicelocator.lookup("java:jboss/exported/FeebackModulEAR/FeedbackModulEJB/TanSessionBean!de.hhbk.feedbackmodul.remoteInterfaces.TanRemoteIF", TanRemoteIF.class);
			List<Tan> list = remote.getAllTans();
			return list;
		}
		catch(NamingException e)
		{
			logger.error("Exception while looking up to the remote Interface 'TanRemoteIF': "+e.getMessage(),e);
			
		} 
		catch (Exception e)
		{
			logger.error("Exception while reading Tans from RemotInterface: "+e.getMessage(),e);
		}
		return new ArrayList<Tan>();	
	}
	
	/* SCHREIBZUGRIFF */
	
	public boolean createUser(User user)
	{
		try
		{
			UserRemoteIF remote = (UserRemoteIF) servicelocator.lookup("java:jboss/exported/FeebackModulEAR/FeedbackModulEJB/UserSessionBean!de.hhbk.feedbackmodul.remoteInterfaces.UserRemoteIF", UserRemoteIF.class);
			remote.createUser(user);
			return true;
		}
		catch(NamingException e)
		{
			logger.error("Exception while looking up to the remote Interface 'UserRemoteIF': "+e.getMessage(),e);
			
		} 
		catch (Exception e)
		{
			logger.error("Exception while creating User from RemotInterface: "+e.getMessage(),e);
		}
		return false;
	}
	
	public boolean updateUser(User user)
	{
		try
		{
			UserRemoteIF remote = (UserRemoteIF) servicelocator.lookup("java:jboss/exported/FeebackModulEAR/FeedbackModulEJB/UserSessionBean!de.hhbk.feedbackmodul.remoteInterfaces.UserRemoteIF", UserRemoteIF.class);
			remote.updateUser(user);
			return true;
		}
		catch(NamingException e)
		{
			logger.error("Exception while looking up to the remote Interface 'UserRemoteIF': "+e.getMessage(),e);
			
		} 
		catch (Exception e)
		{
			logger.error("Exception while updating User from RemotInterface: "+e.getMessage(),e);
		}
		return false;
	}
	
	public boolean deleteUser(User user)
	{
		try
		{
			UserRemoteIF remote = (UserRemoteIF) servicelocator.lookup("java:jboss/exported/FeebackModulEAR/FeedbackModulEJB/UserSessionBean!de.hhbk.feedbackmodul.remoteInterfaces.UserRemoteIF", UserRemoteIF.class);
			remote.deleteUser(user);
			return true;
		}
		catch(NamingException e)
		{
			logger.error("Exception while looking up to the remote Interface 'UserRemoteIF': "+e.getMessage(),e);
			
		} 
		catch (Exception e)
		{
			logger.error("Exception while deleting User from RemotInterface: "+e.getMessage(),e);
		}
		return false;
	}
	
	public boolean createUserRole(UserRole userRole)
	{
		try
		{
			UserRoleRemoteIF remote = (UserRoleRemoteIF) servicelocator.lookup("java:jboss/exported/FeebackModulEAR/FeedbackModulEJB/UserRoleSessionBean!de.hhbk.feedbackmodul.remoteInterfaces.UserRoleRemoteIF", UserRoleRemoteIF.class);
			remote.createUserRole(userRole);
			return true;
		}
		catch(NamingException e)
		{
			logger.error("Exception while looking up to the remote Interface 'UserRoleRemoteIF': "+e.getMessage(),e);
			
		} 
		catch (Exception e)
		{
			logger.error("Exception while creating UserRole from RemotInterface: "+e.getMessage(),e);
		}
		return false;
	}

	public boolean updateUserRole(UserRole userRole)
	{
		try
		{
			UserRoleRemoteIF remote = (UserRoleRemoteIF) servicelocator.lookup("java:jboss/exported/FeebackModulEAR/FeedbackModulEJB/UserRoleSessionBean!de.hhbk.feedbackmodul.remoteInterfaces.UserRoleRemoteIF", UserRoleRemoteIF.class);
			remote.updateUserRole(userRole);
			return true;
		}
		catch(NamingException e)
		{
			logger.error("Exception while looking up to the remote Interface 'UserRoleRemoteIF': "+e.getMessage(),e);
			
		} 
		catch (Exception e)
		{
			logger.error("Exception while updating UserRole from RemotInterface: "+e.getMessage(),e);
		}
		return false;
	}
	
	public boolean deleteUserRole(UserRole userRole)
	{
		try
		{
			UserRoleRemoteIF remote = (UserRoleRemoteIF) servicelocator.lookup("java:jboss/exported/FeebackModulEAR/FeedbackModulEJB/UserRoleSessionBean!de.hhbk.feedbackmodul.remoteInterfaces.UserRoleRemoteIF", UserRoleRemoteIF.class);
			remote.deleteUserRole(userRole);
			return true;
		}
		catch(NamingException e)
		{
			logger.error("Exception while looking up to the remote Interface 'UserRoleRemoteIF': "+e.getMessage(),e);
			
		} 
		catch (Exception e)
		{
			logger.error("Exception while deleting UserRole from RemotInterface: "+e.getMessage(),e);
		}
		return false;
	}
	
	public boolean createAnswer(Answer answer)
	{
		try
		{
			AnswerRemoteIF remote = (AnswerRemoteIF) servicelocator.lookup("java:jboss/exported/FeebackModulEAR/FeedbackModulEJB/AnswerSessionBean!de.hhbk.feedbackmodul.remoteInterfaces.AnswerRemoteIF", AnswerRemoteIF.class);
			remote.createAnswer(answer);
			return true;
		}
		catch(NamingException e)
		{
			logger.error("Exception while looking up to the remote Interface 'AnswerRemoteIF': "+e.getMessage(),e);
			
		} 
		catch (Exception e)
		{
			logger.error("Exception while creating Answer from RemotInterface: "+e.getMessage(),e);
		}
		return false;
	}

	public boolean updateAnswer(Answer answer)
	{
		try
		{
			AnswerRemoteIF remote = (AnswerRemoteIF) servicelocator.lookup("java:jboss/exported/FeebackModulEAR/FeedbackModulEJB/AnswerSessionBean!de.hhbk.feedbackmodul.remoteInterfaces.AnswerRemoteIF", AnswerRemoteIF.class);
			remote.updateAnswer(answer);
			return true;
		}
		catch(NamingException e)
		{
			logger.error("Exception while looking up to the remote Interface 'AnswerRemoteIF': "+e.getMessage(),e);
			
		} 
		catch (Exception e)
		{
			logger.error("Exception while updating Answer from RemotInterface: "+e.getMessage(),e);
		}
		return false;
	}

	public boolean deleteAnswer(Answer answer)
	{
		try
		{
			AnswerRemoteIF remote = (AnswerRemoteIF) servicelocator.lookup("java:jboss/exported/FeebackModulEAR/FeedbackModulEJB/AnswerSessionBean!de.hhbk.feedbackmodul.remoteInterfaces.AnswerRemoteIF", AnswerRemoteIF.class);
			remote.deleteAnswer(answer);
			return true;
		}
		catch(NamingException e)
		{
			logger.error("Exception while looking up to the remote Interface 'AnswerRemoteIF': "+e.getMessage(),e);
			
		} 
		catch (Exception e)
		{
			logger.error("Exception while deleting Answer from RemotInterface: "+e.getMessage(),e);
		}
		return false;
	}
	
	public boolean createAnswerSheet(AnswerSheet answerSheet)
	{
		try
		{
			AnswerSheetRemoteIF remote = (AnswerSheetRemoteIF) servicelocator.lookup("java:jboss/exported/FeebackModulEAR/FeedbackModulEJB/AnswerSheetSessionBean!de.hhbk.feedbackmodul.remoteInterfaces.AnswerSheetRemoteIF", AnswerSheetRemoteIF.class);
			remote.createAnswerSheet(answerSheet);
			return true;
		}
		catch(NamingException e)
		{
			logger.error("Exception while looking up to the remote Interface 'AnswerSheetRemoteIF': "+e.getMessage(),e);
			
		} 
		catch (Exception e)
		{
			logger.error("Exception while creating AnswerSheet from RemotInterface: "+e.getMessage(),e);
		}
		return false;
	}

	public boolean updateAnswerSheet(AnswerSheet answerSheet)
	{
		try
		{
			AnswerSheetRemoteIF remote = (AnswerSheetRemoteIF) servicelocator.lookup("java:jboss/exported/FeebackModulEAR/FeedbackModulEJB/AnswerSheetSessionBean!de.hhbk.feedbackmodul.remoteInterfaces.AnswerSheetRemoteIF", AnswerSheetRemoteIF.class);
			remote.updateAnswerSheet(answerSheet);
			return true;
		}
		catch(NamingException e)
		{
			logger.error("Exception while looking up to the remote Interface 'AnswerSheetRemoteIF': "+e.getMessage(),e);
			
		} 
		catch (Exception e)
		{
			logger.error("Exception while updating AnswerSheet from RemotInterface: "+e.getMessage(),e);
		}
		return false;
	}

	public boolean deleteAnswerSheet(AnswerSheet answerSheet)
	{
		try
		{
			AnswerSheetRemoteIF remote = (AnswerSheetRemoteIF) servicelocator.lookup("java:jboss/exported/FeebackModulEAR/FeedbackModulEJB/AnswerSheetSessionBean!de.hhbk.feedbackmodul.remoteInterfaces.AnswerSheetRemoteIF", AnswerSheetRemoteIF.class);
			remote.deleteAnswerSheet(answerSheet);
			return true;
		}
		catch(NamingException e)
		{
			logger.error("Exception while looking up to the remote Interface 'AnswerSheetRemoteIF': "+e.getMessage(),e);
			
		} 
		catch (Exception e)
		{
			logger.error("Exception while deleting AnswerSheet from RemotInterface: "+e.getMessage(),e);
		}
		return false;
	}
	
	public boolean createAnswerPossibility(AnswerPossibility answerPossibility)
	{
		try
		{
			AnswerPossibilityRemoteIF remote = (AnswerPossibilityRemoteIF) servicelocator.lookup("java:jboss/exported/FeebackModulEAR/FeedbackModulEJB/AnswerPossibilitySessionBean!de.hhbk.feedbackmodul.remoteInterfaces.AnswerPossibilityRemoteIF", AnswerPossibilityRemoteIF.class);
			remote.createAnswerPossibility(answerPossibility);
			return true;
		}
		catch(NamingException e)
		{
			logger.error("Exception while looking up to the remote Interface 'AnswerPossibilityRemoteIF': "+e.getMessage(),e);
			
		} 
		catch (Exception e)
		{
			logger.error("Exception while creating AnswerPossibility from RemotInterface: "+e.getMessage(),e);
		}
		return false;
	}

	public boolean updateAnswerPossibility(AnswerPossibility answerPossibility)
	{
		try
		{
			AnswerPossibilityRemoteIF remote = (AnswerPossibilityRemoteIF) servicelocator.lookup("java:jboss/exported/FeebackModulEAR/FeedbackModulEJB/AnswerPossibilitySessionBean!de.hhbk.feedbackmodul.remoteInterfaces.AnswerPossibilityRemoteIF", AnswerPossibilityRemoteIF.class);
			remote.updateAnswerPossibility(answerPossibility);
			return true;
		}
		catch(NamingException e)
		{
			logger.error("Exception while looking up to the remote Interface 'AnswerPossibilityRemoteIF': "+e.getMessage(),e);
			
		} 
		catch (Exception e)
		{
			logger.error("Exception while updating AnswerPossibility from RemotInterface: "+e.getMessage(),e);
		}
		return false;
	}
	
	public boolean deleteAnswerPossibility(AnswerPossibility answerPossibility)
	{
		try
		{
			AnswerPossibilityRemoteIF remote = (AnswerPossibilityRemoteIF) servicelocator.lookup("java:jboss/exported/FeebackModulEAR/FeedbackModulEJB/AnswerPossibilitySessionBean!de.hhbk.feedbackmodul.remoteInterfaces.AnswerPossibilityRemoteIF", AnswerPossibilityRemoteIF.class);
			remote.deleteAnswerPossibility(answerPossibility);
			return true;
		}
		catch(NamingException e)
		{
			logger.error("Exception while looking up to the remote Interface 'AnswerPossibilityRemoteIF': "+e.getMessage(),e);
			
		} 
		catch (Exception e)
		{
			logger.error("Exception while deleting AnswerPossibility from RemotInterface: "+e.getMessage(),e);
		}
		return false;
	}
	
	public boolean createQuestion(Question question)
	{
		try
		{
			QuestionRemoteIF remote = (QuestionRemoteIF) servicelocator.lookup("java:jboss/exported/FeebackModulEAR/FeedbackModulEJB/QuestionSessionBean!de.hhbk.feedbackmodul.remoteInterfaces.QuestionRemoteIF", QuestionRemoteIF.class);
			remote.createQuestion(question);
			return true;
		}
		catch(NamingException e)
		{
			logger.error("Exception while looking up to the remote Interface 'QuestionRemoteIF': "+e.getMessage(),e);
			
		} 
		catch (Exception e)
		{
			logger.error("Exception while creating Question from RemotInterface: "+e.getMessage(),e);
		}
		return false;
	}

	public boolean updateQuestion(Question question)
	{
		try
		{
			QuestionRemoteIF remote = (QuestionRemoteIF) servicelocator.lookup("java:jboss/exported/FeebackModulEAR/FeedbackModulEJB/QuestionSessionBean!de.hhbk.feedbackmodul.remoteInterfaces.QuestionRemoteIF", QuestionRemoteIF.class);
			remote.updateQuestion(question);
			return true;
		}
		catch(NamingException e)
		{
			logger.error("Exception while looking up to the remote Interface 'QuestionRemoteIF': "+e.getMessage(),e);
			
		} 
		catch (Exception e)
		{
			logger.error("Exception while updating Question from RemotInterface: "+e.getMessage(),e);
		}
		return false;
	}

	public boolean deleteQuestion(Question question)
	{
		try
		{
			QuestionRemoteIF remote = (QuestionRemoteIF) servicelocator.lookup("java:jboss/exported/FeebackModulEAR/FeedbackModulEJB/QuestionSessionBean!de.hhbk.feedbackmodul.remoteInterfaces.QuestionRemoteIF", QuestionRemoteIF.class);
			remote.deleteQuestion(question);
			return true;
		}
		catch(NamingException e)
		{
			logger.error("Exception while looking up to the remote Interface 'QuestionRemoteIF': "+e.getMessage(),e);
			
		} 
		catch (Exception e)
		{
			logger.error("Exception while deleting Question from RemotInterface: "+e.getMessage(),e);
		}
		return false;
	}
	
	public boolean createQuestionSheet(QuestionSheet questionSheet)
	{
		try
		{
			QuestionSheetRemoteIF remote = (QuestionSheetRemoteIF) servicelocator.lookup("java:jboss/exported/FeebackModulEAR/FeedbackModulEJB/QuestionSheetSessionBean!de.hhbk.feedbackmodul.remoteInterfaces.QuestionSheetRemoteIF", QuestionSheetRemoteIF.class);
			remote.createQuestionSheet(questionSheet);
			return true;
		}
		catch(NamingException e)
		{
			logger.error("Exception while looking up to the remote Interface 'QuestionSheetRemoteIF': "+e.getMessage(),e);
			
		} 
		catch (Exception e)
		{
			logger.error("Exception while creating QuestionSheet from RemotInterface: "+e.getMessage(),e);
		}
		return false;
	}

	public boolean updateQuestionSheet(QuestionSheet questionSheet)
	{
		try
		{
			QuestionSheetRemoteIF remote = (QuestionSheetRemoteIF) servicelocator.lookup("java:jboss/exported/FeebackModulEAR/FeedbackModulEJB/QuestionSheetSessionBean!de.hhbk.feedbackmodul.remoteInterfaces.QuestionSheetRemoteIF", QuestionSheetRemoteIF.class);
			remote.updateQuestionSheet(questionSheet);
			return true;
		}
		catch(NamingException e)
		{
			logger.error("Exception while looking up to the remote Interface 'QuestionSheetRemoteIF': "+e.getMessage(),e);
			
		} 
		catch (Exception e)
		{
			logger.error("Exception while updating QuestionSheet from RemotInterface: "+e.getMessage(),e);
		}
		return false;
	}

	public boolean deleteQuestionSheet(QuestionSheet questionSheet)
	{
		try
		{
			QuestionSheetRemoteIF remote = (QuestionSheetRemoteIF) servicelocator.lookup("java:jboss/exported/FeebackModulEAR/FeedbackModulEJB/QuestionSheetSessionBean!de.hhbk.feedbackmodul.remoteInterfaces.QuestionSheetRemoteIF", QuestionSheetRemoteIF.class);
			remote.deleteQuestionSheet(questionSheet);
			return true;
		}
		catch(NamingException e)
		{
			logger.error("Exception while looking up to the remote Interface 'QuestionSheetRemoteIF': "+e.getMessage(),e);
			
		} 
		catch (Exception e)
		{
			logger.error("Exception while deleting QuestionSheet from RemotInterface: "+e.getMessage(),e);
		}
		return false;
	}
	
	public boolean createParticipant(Participant participant)
	{
		try
		{
			ParticipantRemoteIF remote = (ParticipantRemoteIF) servicelocator.lookup("java:jboss/exported/FeebackModulEAR/FeedbackModulEJB/ParticipantSessionBean!de.hhbk.feedbackmodul.remoteInterfaces.ParticipantRemoteIF", ParticipantRemoteIF.class);
			remote.createParticipant(participant);
			return true;
		}
		catch(NamingException e)
		{
			logger.error("Exception while looking up to the remote Interface 'ParticipantRemoteIF': "+e.getMessage(),e);
			
		} 
		catch (Exception e)
		{
			logger.error("Exception while creating Participant from RemotInterface: "+e.getMessage(),e);
		}
		return false;
	}

	public boolean updateParticipant(Participant participant)
	{
		try
		{
			ParticipantRemoteIF remote = (ParticipantRemoteIF) servicelocator.lookup("java:jboss/exported/FeebackModulEAR/FeedbackModulEJB/ParticipantSessionBean!de.hhbk.feedbackmodul.remoteInterfaces.ParticipantRemoteIF", ParticipantRemoteIF.class);
			remote.updateParticipant(participant);
			return true;
		}
		catch(NamingException e)
		{
			logger.error("Exception while looking up to the remote Interface 'ParticipantRemoteIF': "+e.getMessage(),e);
			
		} 
		catch (Exception e)
		{
			logger.error("Exception while updating Participant from RemotInterface: "+e.getMessage(),e);
		}
		return false;
	}

	public boolean deleteParticipant(Participant participant)
	{
		try
		{
			ParticipantRemoteIF remote = (ParticipantRemoteIF) servicelocator.lookup("java:jboss/exported/FeebackModulEAR/FeedbackModulEJB/ParticipantSessionBean!de.hhbk.feedbackmodul.remoteInterfaces.ParticipantRemoteIF", ParticipantRemoteIF.class);
			remote.deleteParticipant(participant);
			return true;
		}
		catch(NamingException e)
		{
			logger.error("Exception while looking up to the remote Interface 'ParticipantRemoteIF': "+e.getMessage(),e);
			
		} 
		catch (Exception e)
		{
			logger.error("Exception while deleting Participant from RemotInterface: "+e.getMessage(),e);
		}
		return false;
	}
	
	public boolean createSurvey(Survey survey)
	{
		try
		{
			SurveyRemoteIF remote = (SurveyRemoteIF) servicelocator.lookup("java:jboss/exported/FeebackModulEAR/FeedbackModulEJB/SurveySessionBean!de.hhbk.feedbackmodul.remoteInterfaces.SurveyRemoteIF", SurveyRemoteIF.class);
			remote.createSurvey(survey);
			return true;
		}
		catch(NamingException e)
		{
			logger.error("Exception while looking up to the remote Interface 'SurveyRemoteIF': "+e.getMessage(),e);
			
		} 
		catch (Exception e)
		{
			logger.error("Exception while creating Survey from RemotInterface: "+e.getMessage(),e);
		}
		return false;
	}

	public boolean updateSurvey(Survey survey)
	{
		try
		{
			SurveyRemoteIF remote = (SurveyRemoteIF) servicelocator.lookup("java:jboss/exported/FeebackModulEAR/FeedbackModulEJB/SurveySessionBean!de.hhbk.feedbackmodul.remoteInterfaces.SurveyRemoteIF", SurveyRemoteIF.class);
			remote.updateSurvey(survey);
			return true;
		}
		catch(NamingException e)
		{
			logger.error("Exception while looking up to the remote Interface 'SurveyRemoteIF': "+e.getMessage(),e);
			
		} 
		catch (Exception e)
		{
			logger.error("Exception while updating Survey from RemotInterface: "+e.getMessage(),e);
		}
		return false;
	}

	public boolean deleteSurvey(Survey survey)
	{
		try
		{
			SurveyRemoteIF remote = (SurveyRemoteIF) servicelocator.lookup("java:jboss/exported/FeebackModulEAR/FeedbackModulEJB/SurveySessionBean!de.hhbk.feedbackmodul.remoteInterfaces.SurveyRemoteIF", SurveyRemoteIF.class);
			remote.deleteSurvey(survey);
			return true;
		}
		catch(NamingException e)
		{
			logger.error("Exception while looking up to the remote Interface 'SurveyRemoteIF': "+e.getMessage(),e);
			
		} 
		catch (Exception e)
		{
			logger.error("Exception while deleting Survey from RemotInterface: "+e.getMessage(),e);
		}
		return false;
	}
	
	public boolean createTan(Tan tan)
	{
		try
		{
			TanRemoteIF remote = (TanRemoteIF) servicelocator.lookup("java:jboss/exported/FeebackModulEAR/FeedbackModulEJB/TanSessionBean!de.hhbk.feedbackmodul.remoteInterfaces.TanRemoteIF", TanRemoteIF.class);
			remote.createTan(tan);
			return true;
		}
		catch(NamingException e)
		{
			logger.error("Exception while looking up to the remote Interface 'TanRemoteIF': "+e.getMessage(),e);
			
		} 
		catch (Exception e)
		{
			logger.error("Exception while creating Tan from RemotInterface: "+e.getMessage(),e);
		}
		return false;
	}

	public boolean updateTan(Tan tan)
	{
		try
		{
			TanRemoteIF remote = (TanRemoteIF) servicelocator.lookup("java:jboss/exported/FeebackModulEAR/FeedbackModulEJB/TanSessionBean!de.hhbk.feedbackmodul.remoteInterfaces.TanRemoteIF", TanRemoteIF.class);
			remote.updateTan(tan);
			return true;
		}
		catch(NamingException e)
		{
			logger.error("Exception while looking up to the remote Interface 'TanRemoteIF': "+e.getMessage(),e);
			
		} 
		catch (Exception e)
		{
			logger.error("Exception while updating Tan from RemotInterface: "+e.getMessage(),e);
		}
		return false;
	}

	public boolean deleteTan(Tan tan)
	{
		try
		{
			TanRemoteIF remote = (TanRemoteIF) servicelocator.lookup("java:jboss/exported/FeebackModulEAR/FeedbackModulEJB/TanSessionBean!de.hhbk.feedbackmodul.remoteInterfaces.TanRemoteIF", TanRemoteIF.class);
			remote.deleteTan(tan);
			return true;
		}
		catch(NamingException e)
		{
			logger.error("Exception while looking up to the remote Interface 'TanRemoteIF': "+e.getMessage(),e);
			
		} 
		catch (Exception e)
		{
			logger.error("Exception while deleting Tan from RemotInterface: "+e.getMessage(),e);
		}
		return false;
	}
	
	
	
	/* REFRESH METHODEN */
	
	public boolean refreshUserList()
	{
		synchronized (userlist) {
			userlist = getAllUser();
			if(userlist.size() > 0)
			{
				return true;
			}
			return false;
		}
		
	}
	
	public boolean refreshUserRoleList()
	{
		synchronized (userRoleList) {
			userRoleList = getAllUserRoles();
			if(userRoleList.size() > 0)
			{
				return true;
			}
			return false;
		}
	}
	
	public boolean refreshAnswerList()
	{
		synchronized (answerList) {
			answerList = getAllAnswers();
			if(answerList.size() > 0)
			{
				return true;
			}
			return false;
		}
	}

	public boolean refreshAnswerSheetList()
	{
		synchronized (answerSheetList) {
			answerSheetList = getAllAnswerSheets();
			if(answerSheetList.size() > 0)
			{
				return true;
			}
			return false;
		}
	}
	
	public boolean refreshAnswerPossibilityList()
	{
		synchronized (answerPossibilityList) {
			answerPossibilityList = getAllAnswerPossibilities();
			if(answerPossibilityList.size() > 0)
			{
				return true;
			}
			return false;
		}
	}
	
	public boolean refreshQuestionList()
	{
		synchronized (questionList) {
			questionList = getAllQuestions();
			if(questionList.size() > 0)
			{
				return true;
			}
			return false;
		}
	}
	
	public boolean refreshQuestionSheetList()
	{
		synchronized (questionSheetList) {
			questionSheetList = getAllQuestionSheets();
			if(questionSheetList.size() > 0)
			{
				return true;
			}
			return false;
		}
	}

	public boolean refreshParticipantList()
	{
		synchronized (participantList) {
			participantList = getAllParticipants();
			if(participantList.size() > 0)
			{
				return true;
			}
			return false;
		}
	}
	
	public boolean refreshSurveyList()
	{
		synchronized (surveyList) {
			surveyList = getAllSurveys();
			if(surveyList.size() > 0)
			{
				return true;
			}
			return false;
		}
	}
	
	public boolean refreshTanList()
	{
		synchronized (tanList) {
			tanList = getAllTans();
			if(tanList.size() > 0)
			{
				return true;
			}
			return false;
		}
	}
	
	/* GETTER + SETTER */
	
	public ServiceLocator getServicelocator() {
		return servicelocator;
	}
	
	public List<User> getUserlist() {
		synchronized (userlist) {
			return userlist;
		}
	}

	public List<UserRole> getUserRoleList() {
		synchronized (userRoleList) {
			return userRoleList;
		}
	}

	public List<Question> getQuestionList() {
		synchronized (questionList) {
		return questionList;
		}
	}

	public List<Answer> getAnswerList() {
		synchronized (answerList) {
			return answerList;
		}
	}

	public List<AnswerPossibility> getAnswerPossibilityList() {
		synchronized (answerPossibilityList) {
			return answerPossibilityList;
		}
	}

	public List<Participant> getParticipantList() {
		synchronized (participantList) {
			return participantList;
		}
	}

	public List<Survey> getSurveyList() {
		synchronized (surveyList) {
			return surveyList;
		}
	}

	public List<AnswerSheet> getAnswerSheetList() {
		synchronized (answerSheetList) {
			return answerSheetList;
		}
	}

	public List<QuestionSheet> getQuestionSheetList() {
		synchronized (questionSheetList) {
			return questionSheetList;
		}
	}

	public List<Tan> getTanList() {
		synchronized (tanList) {
			return tanList;
		}
	}

}
